package cn.xiongxf.pet.delay_cancel;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public  void delayCancel(Long id) throws Exception {
        // 1.创建消费者对象
        DefaultMQProducer producer = new DefaultMQProducer("petSearchMasterMsg_producer_group");
        // 2.连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 3.启动消费者
        producer.start();
        // 4.发送延迟消息
        Message message = new Message("pet", "SearchMsg",id.toString().getBytes(StandardCharsets.UTF_8));
        // 设置延迟消息级别
        message.setDelayTimeLevel(3);
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult);
        // 5.关闭消费者
        producer.shutdown();
    }
}
